package com.ruoyi.applet.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.applet.domain.UsrBrowseTime;
import com.ruoyi.applet.utli.TokenByUsrId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.applet.domain.UsrBrowse;
import com.ruoyi.applet.service.IUsrBrowseService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 热门Controller
 * 
 * @author ruoyi
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/applet")
public class UsrBrowseController extends BaseController
{
    @Resource
    private IUsrBrowseService usrBrowseService;

    @RequestMapping("/usrBrowseList")
    public Object selectUsrBrowseList(){
        return usrBrowseService.selectAllByBrowseGoodsIdUsrBrowseVoList();
    }

    @RequestMapping("/insertBrowse")
    public Object insertBrowseTime(@RequestParam("token") String token,@RequestParam("goodsId") Long goodsId){
        if(usrBrowseService.selectAllByBrowseGoodsId(goodsId) == null){
            Integer count = usrBrowseService.insertAllUsrBrowseTime();
            if(count != 0){
                UsrBrowseTime usrBrowseTime = usrBrowseService.selectBrowseByBrowseTimeId();
                usrBrowseService.insertAllUsrBrowse(TokenByUsrId.tokenByUsrId(token),goodsId,usrBrowseTime.getTimeId());
                return true;
            }
        }
        return false;
    }
}
